package day18.tarena.Thred;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestTime extends Thread  implements ActionListener{
	int t = 100;
	JLabel jl = new JLabel("  2:00:00  ");
	JProgressBar jdt= new JProgressBar(JProgressBar.HORIZONTAL);
	public void actionPerformed(ActionEvent e) {
			this.start();
	}
	
	public void run(){
		for (int h = 1; h >= 0; h--) {
			for (int s = 59; s >= 0; s--) {
				jl.setText(h+":" + s + ":");
				try {
					Thread.sleep(1000);
				} catch (Exception e) {
					e.printStackTrace();
				}
				for (int m = 59; m >= 0; m--) {
					if(m>=10){
						jl.setText(h+":" + s + ":" + m);
					}else if(m<10){
						jl.setText(h+":" + s + ":" +"0"+ m);
					}
					jdt.setValue(t);
					try {
						Thread.sleep(1000);
						jdt.setStringPainted(true) ;
						t--;
					} catch (Exception ae) {
						ae.printStackTrace();
					}
				}
			}
		}
	}
	
	
	public TestTime(){
    	JFrame jf = new JFrame("倒计时");
    	jf.setLayout(new FlowLayout());
    	JButton jb  = new JButton("倒计时开始");
    	jb.addActionListener(this);
    	jf.add(jdt);
    	jf.add(jl);
    	jf.add(jb);
		jf.setLocation(400,400);
		jf.pack();
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	public static void main(String[] args) {
		new TestTime();
	}
}
